# pragma once

# include "cpp_tools_Headers.h"

namespace cpp_tools
{
    /// @brief 获取当前自纪元（epoch）以来的总时间（以秒为单位)
    /// @return 
    double getCurrentTimeAsDouble()
    {
        // 获取当前时间点（以纳秒为单位）
        auto now = std::chrono::high_resolution_clock::now();
        // 转换为自纪元（epoch）以来的总时间（以秒为单位）
        auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(now.time_since_epoch());
        return duration.count();  // 返回时间戳（double类型）
    }

    /// @brief 时钟，可以用来计时
    struct clock
    {
        std::chrono::_V2::system_clock::time_point start;
        std::chrono::_V2::system_clock::time_point end;

        clock()
        {
            start = std::chrono::high_resolution_clock::now();
            end = std::chrono::high_resolution_clock::now();
        }

        /// @brief 计时器（重新）开始计时
        void tic()
        {
            start = std::chrono::high_resolution_clock::now();
        }

        /// @brief 计时器记录一次
        /// @param disp 是否打印
        /// @return 记录时间（ms）
        double toc(bool disp = 1)
        {
            end = std::chrono::high_resolution_clock::now();

            std::chrono::duration<double,std::milli> elapsed = end - start;

            if (disp)
            {
                std::cout << "clock: time = " << elapsed.count() << " ms\n";
            }

            return elapsed.count();
        }
    };
} // namespace cpp_tools

# define TIME_INFO_S "[ " << std::fixed << std::setprecision(8) << cpp_tools::getCurrentTimeAsDouble() <<" ]"
